package com.example.demo2;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements ListFragment.OnTitleClickListener {

    private TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        findViewById(R.id.textView).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // static load fragment

                startActivity(new Intent(MainActivity.this, StaticLoadFragmentActivity.class));

            }
        });

//        ListFragment fragment = new ListFragment();
//        getSupportFragmentManager().beginTransaction().add(R.id.listContainer, fragment).commit();
//        getSupportFragmentManager().beginTransaction().add(R.id.detailContainer, new ListFragment()).commit();

        ListFragment listFragment = ListFragment.newInstance("list");
        getSupportFragmentManager().beginTransaction().
                add(R.id.listContainer, listFragment).commit();
        listFragment.setOnTitleClickListener(this);

        ListFragment detailFragment = ListFragment.newInstance("detail");
        getSupportFragmentManager().beginTransaction().
                add(R.id.detailContainer, detailFragment).commit();
        detailFragment.setOnTitleClickListener(this);


    }


    @Override
    public void onClick(String title) {
        TextView textView = findViewById(R.id.textView);
        textView.setText(title);
    }


}